/**********************************************************************************************************************
 *
 * Project:    mGameEngine
 * File:       dynamicbody.h
 * Author:     twoja stara
 * Created on: 2009-09-25
 *
 **********************************************************************************************************************/

#ifndef DYNAMICBODY_H_
#define DYNAMICBODY_H_

#include "body.h"

namespace mGameEngine
{
namespace Physics
{

/**
 * Dynamic rigid body.
 * Dynamic bodies collide and moves around scene.
 * Each body has specific mass and inertia.
 * Move body by applying forces.
 */
class DynamicBody : public Body
{
protected:
    /**
     * Center of mass.
     */
    Vector3 _cMass;
    bool _cMassSpecified;
    uint8 __padding[3];

    /**
     * Mass.
     */
    float _mass;

    /**
     * Linear movement damping.
     */
    float _linearDamping;
    
    /**
     * Angular movement damping.
     */
    float _angularDamping;

public:
    /**
     * Create dynamic rigid body.
     */
    DynamicBody();

    /**
     * Create dynamic rigid body with specified shape and mass,
     * restitution and friction coefficients.
     * @param shape collision shape.
     * @param mass mass.
     * @param restitution (bounciness) coefficient.
     * @param staticFriction static friction coefficient.
     * @param dynamicFriction dynamic (kinetic) friction coefficient.
     */
    DynamicBody(Shape *shape, float mass, float restitution = 0.5f,
                float staticFriction = 0.5f, float dynamicFriction = 0.4f);

    /**
     * Destroy dynamic rigid body.
     */
    virtual ~DynamicBody();

    /**
     * Get dynamic rigid body mass.
     * @return dynamic rigid body mass.
     */
    float getMass() const
    {
        return _mass;
    }

    /**
     * Set rigid body mass.
     * @param mass mass.
     */
    void setMass(float mass);

    /**
     * Get rigid body center of mass.
     * @return rigid body center of mass.
     */
    const Vector3 &getCenterOfMass() const
    {
        return _cMass;
    }

    /**
     * Set rigid body center of mass.
     * @param cMass center of mass position.
     */
    void setCenterOfMass(const Vector3 &cMass);

    /**
     * Get rigid body linear movement damping coefficient.
     * @return rigid body linear movement damping coefficient.
     */
    float getLinearDamping() const
    {
        return _linearDamping;
    }

    /**
     * Get rigid body angular movement damping coefficient.
     * @return rigid body angular movement damping coefficient.
     */
    float getAngularDamping() const
    {
        return _angularDamping;
    }

    /**
    * Set rigid body movement damping coefficients.
    * @param linearDamping linear movement damping coefficient.
    * @param angularDamping angular movement damping coefficient.
     */
    void setDamping(float linearDamping, float angularDamping);

    /**
     * Put force/momentum to rigid body.
     * @param force force vector.
     * @param radius radius at which force is put.
     */
    virtual void putForce(const Vector3 &force, const Vector3 &radius = Vector3());

    /**
     * Put force/momentum impulse to rigid body.
     * @param impulse force vector.
     * @param radius radius at which force is put.
     */
    virtual void putImpulse(const Vector3 &impulse, const Vector3 &radius = Vector3());

    /**
     * Put acceleration to rigid body.
     * @param acc acceleration vector.
     * @param radius radius at which acceleration is put.
     */
    virtual void putAcceleration(const Vector3 &acc, const Vector3 &radius = Vector3());

    /**
     * Create dynamic rigid body on PhysX scene.
     * @param scene PhysX scene.
     */
    virtual void create(NxScene *scene) const;
};

}
}

#endif // DYNAMICBODY_H_
